package top.ezzz.config;

import org.noear.solon.ai.AiConfig;
import org.noear.solon.ai.chat.ChatConfig;
import org.noear.solon.ai.chat.ChatModel;
import org.noear.solon.ai.chat.tool.MethodToolProvider;
import org.noear.solon.ai.embedding.EmbeddingConfig;
import org.noear.solon.ai.embedding.EmbeddingModel;
import org.noear.solon.ai.rag.Repository;
import org.noear.solon.ai.rag.repository.InMemoryRepository;
import org.noear.solon.ai.rag.repository.WebSearchRepository;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;
import top.ezzz.ai.McpServerTool;

@Configuration
public class SolonAiConfig {


    // @Bean(name = "deepseekChatModel")
    // public ChatModel deepseekChatModel(@Inject("${solon.ai.chat.deepseek}") ChatConfig config) {
    //     MethodToolProvider toolProvider = new MethodToolProvider(new McpServerTool());
    //     return ChatModel.of(config)
    //             .defaultToolsAdd(toolProvider)
    //             .build();
    // }

    @Bean(name = "qwenChatModel")
    public ChatModel qwenChatModel(@Inject("${solon.ai.chat.qwen}") ChatConfig config) {
        MethodToolProvider toolProvider = new MethodToolProvider(new McpServerTool());
        return ChatModel.of(config)
                .defaultToolsAdd(toolProvider)
                .build();
    }


    @Bean(name = "bochaWebRepository")
    public Repository bochaWebRepository(@Inject("${solon.ai.repo.websearch}") AiConfig config) {
        return new WebSearchRepository(null, config);
    }


    @Bean(name = "bgeEmbeddingModel")
    public EmbeddingModel bgeEmbeddingModel(@Inject("${solon.ai.embed.bgem3}") EmbeddingConfig config) {
        return new EmbeddingModel(config);
    }

    @Bean(name = "inMemoryRepository")
    public Repository inMemoryRepository(@Inject("bgeEmbeddingModel") EmbeddingModel model) {
        return new InMemoryRepository(model);
    }


}
